package petrochina.company.electric.model;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.Objects;

/**
 * Socket交互数据
 */
public class SocketMessageData implements Parcelable {

    // type 0:连接传userId 1：发送人工处理至监管
    private int type;
    // 用户Id
    private long userId;
    // 接收人/监管用户Id
    private long checkUserId;
    // 数据json
    private String data;

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        this.userId = userId;
    }

    public long getCheckUserId() {
        return checkUserId;
    }

    public void setCheckUserId(long checkUserId) {
        this.checkUserId = checkUserId;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public static Creator<SocketMessageData> getCREATOR() {
        return CREATOR;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.type);
        dest.writeLong(this.userId);
        dest.writeLong(this.checkUserId);
        dest.writeString(this.data);
    }

    public void readFromParcel(Parcel source) {
        this.type = source.readInt();
        this.userId = source.readLong();
        this.checkUserId = source.readLong();
        this.data = source.readString();
    }

    public SocketMessageData(int type, long userId, long checkUserId, String data) {
        this.type = type;
        this.userId = userId;
        this.checkUserId = checkUserId;
        this.data = data;
    }

    protected SocketMessageData(Parcel in) {
        this.type = in.readInt();
        this.userId = in.readLong();
        this.checkUserId = in.readLong();
        this.data = in.readString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof SocketMessageData)) return false;
        SocketMessageData that = (SocketMessageData) o;
        return getType() == that.getType() && getUserId() == that.getUserId() && getCheckUserId() == that.getCheckUserId() && getData().equals(that.getData());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getType(), getUserId(), getCheckUserId(), getData());
    }

    public static final Creator<SocketMessageData> CREATOR = new Creator<SocketMessageData>() {
        @Override
        public SocketMessageData createFromParcel(Parcel source) {
            return new SocketMessageData(source);
        }

        @Override
        public SocketMessageData[] newArray(int size) {
            return new SocketMessageData[size];
        }
    };
}
